//var STORE_NAME = 'colabox'
//var localServer;
var vlog=new Log;

function captureCallback(url, success, captureId) {
  vlog.log(url + ' captured ' + (success ? 'succeeded' : 'failed'));
}
 
var filesToCapture = [
  'css/content.css',
  'css/ui.css',
  'css/content.css',
  'css/moodatatable.css',
  'scripts/excanvas-compressed.js',
  'scripts/mootools-1.2.3-core-nc.js',
  'scripts/mootools-1.2.3.1-more.js',
  'scripts/mootools-1.2.2.2-more_log.js',
  'scripts/mocha.js',
  'scripts/colabox-init.js',
  'scripts/gears_init.js',
  'scripts/gears_app.js',
  'scripts/notepad-init.js',
  'scripts/notepad-worker.js',
  'scripts/moodatatable.js',
  'images/arrow-right.gif',       
	'images/bg-dropdown.gif',       
	'images/bg-handle-horizontal.gif',
	'images/bg-header.gif', 
	'images/bg-panel-header.gif',
	'images/collapse-expand.gif',      
	'images/dock-tabs.gif',      
	'images/handle-icon-horizontal.gif',
	'images/handle-icon.gif',
	'images/icon.png',         
	'images/icons',                
	'images/knob.gif',
	'images/logo.gif',                  
	'images/slider-area.gif',           
	'images/spacer.gif',                
	'images/spinner-placeholder.gif',   
	'images/spinner.gif',             
  'images/tabs.gif',              
  'images/toolbox-divider.gif',   
  'images/toolbox-divider2.gif',
  'images/icons/cog.gif',
  'images/icons/page.gif',
  'images/icons/page_green.gif',
  'images/icons/page_red.gif',
  'images/icons/sheet.gif',
  'images/icons/windows.gif',
  'images_app/border-2.gif',
	'images_app/border.gif',
	'images_app/button_close.png',
	'images_app/button_login.jpg',
	'images_app/b_help.png',
	'images_app/b_more.png',
	'images_app/b_next.png',
	'images_app/b_prev.png',
	'images_app/b_save.png',
	'images_app/b_search.png',
	'images_app/text_bg.gif',
	'images_app/text_bg2.gif',
	'images_app/user_login.png',
	'images_app/vista_toolbar_back.gif',
	'images_app/vista_toolbar_left.png',
	'images_app/vista_toolbar_right.png',
  'index1.html',
  'pages/notepad.html',
  'pages/panel-tabs.html',
  'pages/optionwindow.html'  
];

var GGears = new Class({
	  Implements: Log,	  
	  STORE_NAME: 'colabox',
	  
    initialize: function(){
    	  this.installed=true;
        if (!window.google || !google.gears) {
        	this.installed=false;        	
        	this.log('uninstall google.gears');
			    return;
			  }
			  this.log('installed google.gears is '+this.installed);
			  
			  try {
			    this.localServer =
			        google.gears.factory.create('beta.localserver');
			        
			  } catch (ex) {
			  	    this.installed=false;
			        
			    return;
			  }
			  
			  this.canServeLocally=this.localServer.canServeLocally(location.pathname);
			  
			  this.log(this.canServeLocally);
			  
    },
    checkProtocol:function(){
	    	if (location.protocol.indexOf('http') != 0) {
			    this.log('This sample must be hosted on an HTTP server');
			    return false;
			  } else {
			    return true;
			  }
    },
    captureCallback2:function(url, success, captureId){
    	this.log(url + ' captured ' + (success ? 'succeeded' : 'failed'));
    	//this.log(url);
    },
    createStore:function(){
	    	  if (!this.checkProtocol()) return;
	 
				  // If the store already exists, it will be opened
				  try {
				    this.localServer.createStore(this.STORE_NAME);
				    this.log('Created the store '+this.STORE_NAME);
				  } catch (ex) {
				    this.log('Could not create store: ' + ex.message);
				  }
    },
    capture:function(){
    	    this.createStore();
			  	store = this.localServer.openStore(this.STORE_NAME);
				  if (!store) {
				    this.log('Please create a store for the captured resources');
				    return;
				  }
				 
				  this.log('Capturing...');
				 
				  // Capture this page and the js library we need to run offline.
				  store.capture(filesToCapture, captureCallback);    	
    },
    removeStore:function(){
    	 // We call openStore() to test for it's existence prior to removing it
			  if (this.localServer.openStore(this.STORE_NAME)) {
			    this.localServer.removeStore(this.STORE_NAME);
			    this.log('Removed the store');
			  } else {
			    this.log('The store does not exist');
			  }
    }
    
    
});






